/**
 * Created by shudong.msd(风骐) on 2016/4/17.
 */


"use strict";

app.controller('commonWaitingCtrl',['$rootScope','$scope','$state','$http',function($rootScope,$scope,$state,$http){

    $rootScope.isLoading = false;
    $rootScope.newMissionType = 0;

    var comutil = new commUtils();

    $scope.buildMn = function($event){
        var ele = angular.element($event.target);
        ele.attr("disabled",true);
        $http.post(UrlMappings.BUILD_NEW_MISSION,comutil.getSearchData(),{
            params : {
                'access_token':comutil.getTocken()
            },
            headers: {
                'Accept':'application/json',
                'Content-Type': 'application/json'
            }
        }).success(function(data){
            ele.attr("disabled",null);
            if(data){
                $rootScope.isLoading = false;
                if($rootScope.newMissionType==0){
                    $state.go('main.search.detail',{'type':'tv'});
                }else if($rootScope.newMissionType==1){
                    $state.go('main.search.detail',{'type':'variety'});
                }else{
                    $state.go('main.index.detail');
                }

            }else{
                alert('任务创建失败');
            }
        }).error(function(data,status){
            if(status=='401')comutil.logout($state);
        });

    }

}]);